import junit.framework.TestCase;

public class StringBufferDemoTest extends TestCase {
    StringBuffer buffer1 = new StringBuffer();
    StringBuffer buffer2 = new StringBuffer("i am a student");
    StringBuffer buffer3 = new StringBuffer("i like java");
    StringBufferDemo stringBufferDemo = new StringBufferDemo();
    @Test
    public void testcharAt() {
        buffer1.append('h');
        buffer1.append("ello java");
        assertEquals('l',buffer1.charAt(2));
        assertEquals('h',buffer1.charAt(0));
        assertEquals('k',stringBufferDemo.setBuffer().charAt(1));
    }
    @Test
    public void testlength(){
        assertEquals(0,buffer1.length());
        assertEquals(14,buffer2.length());
        assertEquals(11,buffer3.length());
        assertEquals(8,stringBufferDemo.setBuffer().length());
    }
    @Test
    public void testcapacity(){
        assertEquals(16,buffer1.capacity());
        assertEquals(30,buffer2.capacity());
        assertEquals(27,buffer3.capacity());
        assertEquals(16,stringBufferDemo.setBuffer().capacity());
    }
    public void testToString(){
        assertEquals("",buffer1.toString());
        assertEquals("i am a student",buffer2.toString());
        assertEquals("i like java",buffer3.toString());
        assertEquals("jkjxlkjc",stringBufferDemo.setBuffer().toString());
    }
    public void testIndexOf(){
        assertEquals(0,buffer1.indexOf(""));
        assertEquals(2,buffer2.indexOf("am a st"));
        assertEquals(7,buffer3.indexOf("java"));
        assertEquals(2,stringBufferDemo.setBuffer().indexOf("jxlk"));
    }

}